import os
import sys
import configparser

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

from utils.DBHelper import DBHelper
from utils.DBHelper import logger
from apis.wea import get_wea_data
from apis.yq import get_yq_data


if __name__ == "__main__":
    config = configparser.ConfigParser()
    config.read("./config/db.ini")
    DBHandler = DBHelper(
        config.get("MYSQL", "host"),
        config.get("MYSQL", "user"),
        config.get("MYSQL", "pwd"),
        config.get("MYSQL", "db"),
        int(config.get("MYSQL", "port")),
    )
    # DbHandle.insertDB("insert into author (name) values ('NAME')")
    # DbHandle.deleteDB("delete from author where id=2")
    # res = DbHandle.selectDB("select * from sys_job_log")
    yq_table = {"address": config.get("TABLE", "address")}
    wea_table = {
        "day": config.get("TABLE", "day"),
        "hour": config.get("TABLE", "hour"),
        "now": config.get("TABLE", "now"),
    }
    get_yq_data(DBHandler, logger, yq_table)
    get_wea_data(DBHandler, logger, wea_table)
    DBHandler.closeCursor()
    DBHandler.closeDB()
    print(">>> all ok!")
    print(">>> exit()")
